#include <iostream>
#include <algorithm>
using namespace std;
constexpr int MAXN = 100;
int N, M, sum; // N表示宽, M表示长
char Field[MAXN][MAXN];
void solve();
void dfs(int x, int y);
int main() {
    #ifndef ONLINE_JUDGE
    freopen("./input.txt", "r", stdin);
    // freopen("./out.txt", "w", stdout);
    #endif
    cin >> N >> M;
    for (int i = 0; i < N; i++) 
        for (int j = 0; j < M; j++)
            cin >> Field[i][j];
    solve();
}

void solve() {
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            if (Field[i][j] == 'W') {
                sum++;
                dfs(i, j);
            }
        }
    }
    cout << sum << endl;
}

int dxdy[][8] = {
    {-1, 0, 1, -1, 1, -1, 0, 1},
    {-1, -1, -1, 0, 0, 1, 1, 1}
};

bool check(int x, int y) {
    if (x >= 0 && x < N && y >= 0 && y < M && Field[x][y] == 'W') return true;
    return false;
}

void dfs(int x, int y) {
    Field[x][y] = '.';
    for (int i = 0; i < 8; i++) {
        int nx = x + dxdy[0][i];
        int ny = y + dxdy[1][i];
        if (check(nx, ny)) dfs(nx, ny);
    }
}